(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.category.nodeController', categoryController);
	categoryController.$inject = ['$scope', 'categoryService'];
	function categoryController($scope, categoryService) {
		$scope.limitTreeApi = {};
		$scope.limitData = [];
		$scope.limitSelected = function(limit) {
			if (limit.type == 'ROOT') {
				$scope.go('cda.category.cate', limit);
			} else if (limit.type == 'CATEGORY') {
				$scope.go('cda.category.cate.cateView', limit);
			} else if (limit.type == 'NODE') {
				$scope.go('cda.category.cate.nodeView', limit);
			} else {
				$scope.go('cda.category.cate', limit);
			}
		};
		categoryService.getCategoryTree().then(function(response){
			$scope.limitData = response.data || [];
		});
		$scope.addLimit = function() {
			var selectedLimit = $scope.limitTreeApi.get_selected_branch();
			return $scope.limitTreeApi.add_branch(selectedLimit, {
				label : 'New Limit',
				data : {
					category : selectedLimit.data.category,
					description : 'limit description'
				}
			});
		};
	};
})(angular);